# 读取日志文件
import os
import shutil


# 获取文件路径
def get_file_path(file_name):
	return os.path.join(os.path.dirname(os.path.abspath(__file__)), "files", file_name)


# ip = "223.73.89.192"
# num = 0
# # 读取数据 日志分析，计算某用户`223.73.89.192`访问次数。日志文件如下：`access.log`
# with open(file=get_file_path("access.log"), mode='rt', encoding='utf-8') as file_log:
# 	for line in file_log:
# 		# if line.split(" ")[0] == ip:
# 		# 	num += 1
# 		# 避免层级太深
# 		if not line.split(" ")[0] == ip:
# 			continue
# 		num += 1
# 	print(num)
# 日志分析 升级，计算所有用户的访问次数。
# 用户IP字典
# user_dict = {}
# with open(file=get_file_path("access.log"), mode='rt', encoding='utf-8') as file_log:
# 	for i in file_log:
# 		user_ip = i.split(" ")[0]
# 		if user_ip in user_dict:
# 			user_dict[user_ip] += 1
# 		else:
# 			user_dict[user_ip] = 1
# print(user_dict)

# with open(get_file_path("stock.txt"),mode='rt',encoding='utf-8') as file_stock:
# 	res = file_stock.readline()
# 	print(res)
# 	for line in file_stock:
# 		price = line.split(",")[2]
#
# 		if float(price) > 20:
# 			print(line.strip())


# with open(get_file_path("ha.conf"), mode="r", encoding="utf-8") as file_read, \
# 		open(get_file_path("newcon.conf"), mode="w", encoding="utf-8") as file_write:
# 	for line in file_read:
# 		read_line = line.replace("luffycity", "pythonav")
# 		file_write.write(read_line)
# # 将新写的文件覆盖掉原先的文件
# shutil.move(get_file_path("newcon.conf"),get_file_path("ha.conf"))

